package testcase.doctor;

import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.doctor.GetAssistants;
import common.Host;
import common.TestData;
/**
 * 帮忙医医生端获取助理GetAssistants接口测试用例
 * @author lyn
 */
public class TestGetAssistants 
{
	/**
	 * 帮忙医医生端获取助理GetAssistants接口测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
	@DataProvider (name = "Test")
	public static String[][] testGetAssistantsDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData td = new TestData("doctor/TestGetAssistants.xml");
		return td.getParam();	
	}
	/**
	 * 帮忙医医生端获取助理GetAssistants接口生产环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
	@DataProvider (name = "Prod")
	public static String[][] ProdGetAssistantsDataProvider() throws Exception
	{
		Host.setup("Prod");
		TestData td = new TestData("doctor/TestGetAssistants.xml");
		return td.getParam();	
	}	
	@Test (dataProvider = "Test", groups = {"Test"})
	/**
	 * 帮忙医医生端获取助理GetAssistants测试环境接口测试用例
	 * @param caseName - 用例名称
	 * @param doctorID - 医生ID
	 * @throws Exception
	 */
	public void testGetAssistantsTestCase(String caseName, String doctorID) throws Exception
	{

		//调用接口并将接口返回数据转换成json格式
		
		String result = GetAssistants.options(doctorID);	
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}
		//设置检查点
		JSONArray CheckData;
		String assistantinfo;
		switch (caseName)
		{
		case "Success":
			// 检查点：接口返回Data内的第一个数组是否为空
			CheckData = jsonResult.getJSONArray("Data");
			assistantinfo=CheckData.getString(0);
			Assert.assertEquals(assistantinfo.isEmpty(), false);
		break;	
		case "DoctorIDError":
			//接口返回Data字段是否为空
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(), false);	
		break;	
		case "NoDoctorID":
			// 接口返回数据是否为空		
			Assert.assertNull(jsonResult); 
		break;	
		}
	}
	@Test (dataProvider = "Prod", groups = {"Prod"})
	/**
	 * 帮忙医医生端获取助理GetAssistants接口生产环境测试用例
	 * @param caseName - 用例名称
	 * @param doctorID - 医生ID
	 * @throws Exception
	 */
	public void ProdGetAssistantsTestCase(String caseName, String doctorID) throws Exception
	{

		//调用接口并将接口返回数据转换成json格式
		
		String result = GetAssistants.options(doctorID);	
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}
		//设置检查点
		JSONArray CheckData;
		String assistantinfo;
		switch (caseName)
		{
		case "Success":
			// 检查点：接口返回Data内的第一个数组是否为空
			CheckData = jsonResult.getJSONArray("Data");
			assistantinfo=CheckData.getString(0);
			Assert.assertEquals(assistantinfo.isEmpty(), false);
		break;	
		case "DoctorIDError":
			//接口返回Data字段是否为空
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(), false);	
		break;	
		case "NoDoctorID":
			// 接口返回数据是否为空		
			Assert.assertNull(jsonResult); 
		break;	
		}
	}
}
